<template>
  <el-row id="agentPage">
    <el-col>
      <el-form :inline="true">
        <el-form-item>
          <el-input v-model="userNameStr" size="small" placeholder="真实姓名" style="margin-top:2px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="phoneStr" size="small" placeholder="手机号" style="margin-top:2px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="search" size="small" style="line-height:14px;vertical-align: top;">查询
          </el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-table :data="agentList" v-loading="listLoading" border style="width: 100%; font-size: 12px;"
              row-class-name="tabRow" tooltipEffect="light">
      <el-table-column align="center" label="指定" width="50">
        <template scope="scope">
          <el-radio class="radio" v-model="radio" @change.native="agentPop(scope.row.userName,scope.row.id)" :label="scope.row.userName"></el-radio>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="loginName" label="用户名"></el-table-column>
      <el-table-column align="center" prop="userName" label="姓名"></el-table-column>
      <el-table-column align="center" prop="phone" label="手机号"></el-table-column>
    </el-table>
    <el-col :span="24" class="toolbar" style="margin-top: 15px;" v-show="!listLoading">
      <el-pagination id="pagination" layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 30]" @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :page-size="pageSize" :current-page="page" :total="total" style="float:right;">
      </el-pagination>
    </el-col>
  </el-row>
</template>

<script type="text/ecmascript-6">
  import {resetBreads, sessionOut} from '../../smartlight/common/js/util.js'
  export default {
    data () {
      return {
        userNameStr: '',
        phoneStr: '',
        loginType: '',
        companyId: 0,
        listLoading: false,
        agentList: [],
        total: 2,
        page: 1,
        pageSize: 10,
        agentId: 0,
        agentName: '',
        radio: ''
      }
    },
    methods: {
      agentPop (userName, id) {
        this.agentId = id
        this.agentName = userName
      },
      // 分页插件查询方法-条数
      handleSizeChange (val) {
        this.pageSize = val
        this.initAccountList()
      },
      // 分页插件查询方法-页数
      handleCurrentChange (val) {
        this.page = val
        this.currentPage = val
        this.initAccountList()
      },
      search () {
        this.initAccountList()
      },
      // 初始化分页查询用户信息
      initAccountList () {
        this.listLoading = true
        var para = {
          pageNumber: this.page,
          pageSize: this.pageSize,
          userName: this.userNameStr,
          phone: this.phoneStr,
          type: this.loginType,
          op: 'page',
          companyId: this.companyId,
          operateType: 3
        }
        this.$http.post('/smartLight/web/baseAccount/getList.htm', para).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.total = resBody.result.totalElements
            this.agentList = resBody.result.content
            this.listLoading = false
          } else if (resBody.isSuccess === 2) {
            this.listLoading = false
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      }
    },
    mounted () {
      resetBreads(this)
      var user = sessionStorage.getItem('user')
      if (user) {
        user = JSON.parse(user)
        this.companyId = user.companyId
        this.loginType = user.type
        this.initAccountList()
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
#agentPage
  .el-radio__label
    display: none
</style>
